package com.imooc.example.springtxpa.web;

import com.imooc.example.springtxpa.dao.CustomerRepository;
import com.imooc.example.springtxpa.domain.Customer;
import com.imooc.example.springtxpa.service.CustomerServiceInAnnotation;
import com.imooc.example.springtxpa.service.CustomerServiceInCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linzou@linkdoc.com
 * @ClassName: CustomerResources
 * @Description:
 * @date 2019/1/1 12:10 PM
 */
@RestController
@RequestMapping("/api/customer")
public class CustomerResource {

    @Autowired
    private CustomerServiceInCode customerServiceInCode;
    @Autowired
    private CustomerServiceInAnnotation customerServiceInAnnotation;
    @Autowired
    private CustomerRepository customerRepository;

    @PostMapping("/code")
    public Customer createInCode(@RequestBody Customer customer){
        return customerServiceInCode.create(customer);
    }

    @PostMapping("/annotation")
    public Customer createInAnnotation(@RequestBody Customer customer){
        return customerServiceInAnnotation.create(customer);
    }

    @GetMapping("/all")
    public List<Customer> getAll(){
        return customerRepository.findAll();
    }

}
